using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

/// <summary>
/// ������������
/// </summary>
public class IceStrategy : AttackStrategyBase
{
    public GameObject iceBulletPrefab;
    public float freezeDuration = 3f;
    public float slowFactor = 0.4f;

    public IceStrategy(SkillData data)
    {
        AttackData = data;
    }

    public override void Execute(Entity target)
    {
        base.Execute(target);

        if (target == null)
        {
            Logger.LogWarning("IceStrategy", $"{Owner?.name} 攻击目标无效");
            return;
        }

        if (AttackData == null || AttackData.BulletData == null)
        {
            Logger.LogError("IceStrategy", $"{Owner?.name} 缺少子弹数据");
            return;
        }

        var bulletData = AttackData.BulletData;
        var bullet = BulletPool.Instance.GetBullet(bulletData);
        
        if (bullet == null)
        {
            Logger.LogError("IceStrategy", $"无法获取子弹：{bulletData.BulletType}");
            return;
        }

        // 设置子弹位置
        Vector3 startPos = Owner.transform.position;
        if (bulletData.OffVec3 != Vector3.zero)
        {
            startPos += bulletData.OffVec3;
        }
        bullet.transform.position = startPos;

        var movement = MoveStrategyFactory.Create(bulletData.MoveData);
        bullet.Initialize(
            owner: Owner,
            movement: movement
        );

        AnimateShooting();
        
        Logger.Log("IceStrategy", $"{Owner?.name} 发射冰弹攻击 {target.name}");
    }

    private void AnimateShooting()
    {
        DOTween.Sequence()
            .Append(Owner.transform.DOShakeScale(0.1f, 0.2f))
            .AppendCallback(() => Owner.GetComponent<Animator>().SetTrigger("Shoot"));
    }
}
